package com.assessment.controller;

import com.assessment.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 上传文件的接口
 */
@CrossOrigin
@RestController
public class UploadController {
    private final UploadService service;

    public UploadController(UploadService service) {
        this.service = service;
    }

    @ResponseBody
    @PostMapping("/admin/upload/{filePath}")
    // 接收文件、文件存储地址，将文件存储
    public Map<String, Object> oneFile(MultipartFile file, @PathVariable("filePath") String filePath) {
        return service.uploadFile(file, filePath);
    }
}
